package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Slideshow;
import com.ruoyi.system.service.ISlideshowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图Controller
 *
 * @author ...
 * @date 2022-03-18
 */
@RestController
@RequestMapping("/system/slideshow")
public class SlideshowController extends BaseController {
    @Autowired
    private ISlideshowService slideshowService;

    /**
     * 查询轮播图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Slideshow slideshow) {
        startPage();
        List<Slideshow> list = slideshowService.selectSlideshowList(slideshow);
        return getDataTable(list);
    }

    /**
     * 获取轮播图详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(slideshowService.selectSlideshowById(id));
    }

    /**
     * 新增轮播图
     */
    @PostMapping
    public AjaxResult add(@RequestBody Slideshow slideshow) {
        slideshow.setCreateUser(SecurityUtils.getUserId().intValue());
        slideshow.setCreateTime(DateUtils.getNowDate());
        return toAjax(slideshowService.insertSlideshow(slideshow));
    }

    /**
     * 修改轮播图
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Slideshow slideshow) {
        slideshow.setUpdateUser(SecurityUtils.getUserId());
        slideshow.setCreateTime(DateUtils.getNowDate());
        return toAjax(slideshowService.updateSlideshow(slideshow));
    }

    /**
     * 删除轮播图
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(slideshowService.deleteSlideshowByIds(ids));
    }
}
